const axios = require('axios');
const api = require('../../api');

module.exports = {
    get: (url, data, success) => {
        try {
            const mod = url.split('.')[0]; const
                impl = url.split('.')[1];
            axios({ method: 'get', url: `${api.context}${api.url[mod][impl]}`, data })
                .then((res) => {
                    success && success(res.data);
                })
                .catch((error) => {
                    alert(error);
                });
        } catch (e) {
            alert('请求url不正确！');
        }
    },
    post: (url, data, success) => {
        try {
            const mod = url.split('.')[0]; const
                impl = url.split('.')[1];
            axios({ method: 'post', url: `${api.context}${api.url[mod][impl]}`, data })
                .then((res) => {
                    success && success(res.data);
                })
                .catch((error) => {
                    alert(error);
                });
        } catch (e) {
            alert('请求url不正确！');
        }
    },
};